<template>
  <a-config-provider
    :theme="{
      token: {
        colorPrimary: '#00b96b',
        algorithm: theme.compactAlgorithm,
        borderRadius: 0,
      },
    }"
  ></a-config-provider>
  <RouterView />
</template>
<script setup>
import { onMounted } from "vue";
import { useRouter } from "vue-router";
import { theme } from "ant-design-vue";

const router = useRouter();

onMounted(() => {
  if (
    localStorage.getItem("token") != undefined &&
    localStorage.getItem("token") != "undefined" &&
    localStorage.getItem("token").length > 0
  ) {
    fetch("/api/v1/user/check-token", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${localStorage.getItem("token")}`,
      },
    })
      .then((res) => res.json())
      .then((arm) => {
        if (arm.ok) {
          localStorage.setItem("token", arm.data);
          router.push("/index");
        }
      })
      .catch(() => localStorage.removeItem("token"));
  } else {
    router.push("/login");
  }
});
</script>
<style>
.ToolBar {
  padding: 4px;
  border-bottom: 1px #e0e0e0 solid;
}

.ToolBarDark {
  padding: 4px;
  border-bottom: 1px darkblue solid;
  background: linear-gradient(darkblue, black);
}

.ToolBarBottomDark {
  padding: 4px;
  border-top: 1px darkblue solid;
  background: linear-gradient(black, darkblue);
}

.ListItem {
  padding: 0 4px;
}

.ListItem:hover {
  cursor: pointer;
}

.ListItem.active {
  background-color: #e1faeb;
}

span.HelpInfo {
  color: silver;
  font-size: smaller;
}

.ant-form-item {
  margin-bottom: 4px;
}

.ant-form-vertical .ant-form-item-label {
  padding: 0;
}

.ant-page-header {
  padding: 0;
}

pre {
  white-space: pre-wrap; /* 保持空白符序列，但是正常地进行换行 */
  word-wrap: break-word; /* 在长单词或 URL 地址内部进行换行 */
  white-space: -moz-pre-wrap; /* Mozilla 的支持 */
  white-space: -pre-wrap; /* Opera 4-6 的支持 */
  white-space: -o-pre-wrap; /* Opera 7 的支持 */
}
</style>
